<?php
include_once "lib/config.php";
include_once "header.php";


if(isset($_POST['blog_id']) && $_POST['blog_id']>0)
{
	$conditionarr=array(":blog_id"=>$_POST['blog_id']);
    $postinfo=DB::fetch_array(DB::query("select * from af_blogs where blog_id=:blog_id",$conditionarr));
    
    if(isset($postinfo[0]))
    {
        $data=$postinfo[0];
        
        $qryLinks="select * from  af_blog_links where blog_id='".$data["blog_id"]."'";
		$arrBlogLinks=DB::fetch_array(DB::query($qryLinks,array()));
        
    }
    else
    {
        $data=array();
    }
    
   
}

?>
  		<div class="container_12" id="main_div">
           <form action="" method="post">
			<br>
			<div class="grid_12" >
		    	<?php
            	if(isset($msg_success) && $msg_success!="")
            	{
            	?>
                <div>
                    <span class="notification n-success"><?php echo $msg_success; ?></span>
                </div>
                <?php
                }
                if(isset($msg_error) && $msg_error!="")
                {
                ?>
                <span class="notification n-error"><?php echo $msg_error; ?></span>
                <?php
				}
                ?>
		        <div class="module" >
		        		
		             <h2><span onclick="toggle_div('basic_body','toogleimg');" ><img src="images/desc.gif" height="5px" id="toogleimg">&nbsp;&nbsp;Blog Details</span></h2>
		                
		             <div class="module-body" id="basic_body">
		                	<p>
		                        <label>Title</label>
		                        <div><?php if(isset($data['blog_title']) && $data['blog_title']!=Null)echo $data['blog_title']; ?></div>  
		                    </p>
		                    <p>
		                        <label>Image</label>
		                        <?php if(isset($data['blog_image']) && $data['blog_image']!=Null && $data['blog_image']!="")
                                {
                                    ?>
                                    <img src="<?php echo "../uploads/image_crop.php?image=/uploads/blog_images/".$data["blog_image"]."&width=150&height=150&cropratio=150:150" ?>"/>  
                                    <?php
                                }
                                ?>
		                    </p>
		                  	<p>
		                        <label>Blog Text</label>
		                        <div><?php if(isset($data['blog_description']) && $data['blog_description']!=Null)echo $data['blog_description']; ?></div>
		                        
		                    </p>
		                <?php
		                	if(count($arrBlogLinks)>0)
		                	{
						?>
							<p>
		                        <label>Links</label>
		                        <div>
		                        	<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border:0px solid #ffffff;">
		                        <?php
		                        	for($i=0; $i<count($arrBlogLinks);$i++)
		                        	{
								
								?>
										<tr>
		                        			<td><a href="<?php echo $arrBlogLinks[$i]["blog_link"] ?>" target="_blank"><?php echo $arrBlogLinks[$i]["blog_link"] ?></a></td>
										</tr>
								<?php		
									}
								?>		
									</table>
								</div>
		                        
		                    </p>
						<?php		
							}
						?>    
		                    
		                    <p>
		                        <label>Status</label>
		                        <?php if($data["status"]=="0"){ echo "Active"; } else if($data["status"]=="1"){ echo "De-activate" ;} ?>
		                    </p>
                            
                            
                            
                            
		             </div> <!-- End .module-body -->
		
		        </div>  <!-- End .module -->
				
		    </div>
		    
		    <div class="grid_12">
		    <fieldset>
		    	&nbsp;
		    	<input type="hidden" id="post_id" name="post_id" value="<?php if(isset($_POST['post_id'])){ echo $_POST['post_id']; } ?>">
		        <!--<input class="submit-green" type="submit" name="save" value="Submit" />--> 
		        <input class="submit-gray" type="button" value="Back" onclick="window.location='view_blogs.php?bpid=<?php echo $data['blog_page_id']; ?>'" />
		    </fieldset>
		    </div>
		    <div style="clear:both;"></div>
		 </form>    
        </div> <!-- End .container_12 -->
		
<?php include_once("footer.php"); ?>           
<?php
if(isset($msg_success) && $msg_success!="")
{
	$notymessage=$msg_success;
	$msgtype="success";
}
else if(isset($msg_error) && $msg_error!="")
{
	$msgtype="error";
	$notymessage=$msg_error;
}
else
{
	$msgtype="";
}
if($msgtype!="")
{
?>        
<script language="javascript">
	$(document).ready(function(){
		
		var options = $.parseJSON('{"text":"<?php echo $notymessage; ?>","layout":"top","type":"<?php echo $msgtype; ?>"}');
		noty(options);
		
	});
</script>  
<?php
}
?>
<script>

function validateaddeditpost()
{
	
	if(trim(document.getElementById("name").value)=="")
	{
		alertify.alert("Post title field is required!");
		document.getElementById("name").focus();
		return false;
	}
	else if(trim(document.getElementById("type").value)=="")
	{
		alertify.alert("Post Type field is required!");
		document.getElementById("type").focus();
		return false;
	}
    else if(trim(document.getElementById("link").value)=="")
	{
		alertify.alert("Post URL field is required!");
		document.getElementById("link").focus();
		return false;
	}
    else if(trim(document.getElementById("post_photo").value)=="" && trim(document.getElementById('image_url').value)=="")
	{
		alertify.alert("Post image field is required!");
		document.getElementById("post_photo").focus();
		return false;
	}
    else if(trim(document.getElementById("smalldescription").value)=="")
	{
		alertify.alert("Post small description of maximum 50 characters is required!");
		document.getElementById("smalldescription").focus();
		return false;
	}
}
</script>       